package org.begincode.web;

import com.begincode.common.util.ResultUtil;
import org.begincode.core.model.CourseLabel;
import org.begincode.core.model.CourseLevel;
import org.begincode.core.model.CourseType;
import org.begincode.course.handler.CourseHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by yangsj on 2016/4/30.
 */
@Controller
public class CourseController {
    Logger logger = LoggerFactory.getLogger(CourseController.class);
    @Resource
    private CourseHandler courseHandler;

    @RequestMapping("")
    public String courses(Model model){
        model.addAttribute("courses",courseHandler.getCourses());
        model.addAttribute("levels",courseHandler.getCourseLevels());
        model.addAttribute("types",courseHandler.getCourseTypes());
        return "page/course_list";
    }
    /**
     * 查看课程类型
     * */
    @RequestMapping("/course/courseTypes")
    @ResponseBody
    public Object courseTypes(){
       List<CourseType> courseTypes =  courseHandler.getCourseTypes();
        return ResultUtil.buildSuccess(courseTypes);
    }

    /**
     * 查看课程级别
     * */
    @RequestMapping("/course/courseLevels")
    @ResponseBody
    public Object courseLevels(){
        List<CourseLevel> courseLevels = courseHandler.getCourseLevels();
        return ResultUtil.buildSuccess(courseLevels);
    }
    /**
     * 查看课程级别
     * */
    @RequestMapping("/course/courseLabels")
    @ResponseBody
    public Object courseLabels(){
        List<CourseLabel> courseLabels = courseHandler.getCourseLabels();
        return ResultUtil.buildSuccess(courseLabels);
    }

}
